package com.hscy.push.controller.request;
import cn.jiyun.common.config.Result;
import cn.jiyun.entity.XmNotification;
import com.hscy.push.MessageOpenFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@RestController
@RequestMapping("/dingshi")
@Component //定时任务
@CrossOrigin
public class MyStu {
    private Integer id2 = null;
    private String formattedDate2 = null;
    private XmNotification notification2=null;
    @Autowired
    PushMessageController push ;
    @Resource
    private MessageOpenFeign messageOpenFeign;
    @RequestMapping("/renwu")
    public Result renwu(Integer id , String formattedDate){
        id2=id;
        XmNotification notification = messageOpenFeign.findById2(id2);
        formattedDate2=formattedDate;
        notification2=notification;
        System.out.println("111111111111111111111"+notification);
        System.out.println("2222222222222222222222"+formattedDate2);
        return Result.ok("定时任务执行成功！");
    }
    @Scheduled(cron = "* * * * * *")//每秒执行一次
    public void show(){
        LocalDateTime now = LocalDateTime.now();
        // 定义日期时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm");
        String nowString = formatter.format(now);
        if(nowString.equals(formattedDate2)){
            System.out.println("执行了1111111111111111111111111111");
            push.pushMessage(id2);
            System.exit(0);
        }
    }
}
